import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index')
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/example',
    component: Layout,
    redirect: '/example/user',
    name: 'Example',
    meta: { title: '系统设置', icon: 'example' },
    children: [
      // {
      //   path: 'image',
      //   name: 'Image',
      //   component: () => import('@/views/log/image'),
      //   meta: { title: '图片', icon: 'table' }
      // },
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/user/index'),
        meta: { title: '用户信息列表', icon: 'table' }
      },
      {
        path: 'editUser',
        name: 'EditUser',
        hidden: true,
        component: () => import('@/views/user/editUser'),
        meta: { title: '编辑用户信息', icon: 'table' }
      },
      {
        path: 'addUser',
        name: 'AddUser',
        hidden: true,
        component: () => import('@/views/user/addUser'),
        meta: { title: '添加用户信息', icon: 'table' }
      },

      {
        path: 'log',
        name: 'Log',
        component: () => import('@/views/log'),
        meta: { title: '操作日志', icon: 'table' }
      }
    ]
  },

  {
    path: '/lab',
    component: Layout,
    redirect: '/lab/labList',
    children: [{
      path: 'labList',
      name: 'LabList',
      component: () => import('@/views/lab/labList'),
      meta: { title: '实验室信息管理', icon: 'dashboard' }
    },
    {
      path: 'editLab',
      name: 'EditLab',
      hidden: true,
      component: () => import('@/views/lab/editLab'),
      meta: { title: '编辑实验室信息', icon: 'table' }
    },
    {
      path: 'addLab',
      name: 'AddLab',
      hidden: true,
      component: () => import('@/views/lab/addLab'),
      meta: { title: '添加实验室信息', icon: 'table' }
    }]
  },

  {
    path: '/plan',
    component: Layout,
    redirect: '/plan/planList',
    children: [{
      path: 'planList',
      name: 'PlanList',
      component: () => import('@/views/plan/planList'),
      meta: { title: '招聘计划信息管理', icon: 'dashboard' }
    },
    {
      path: 'editPlan',
      name: 'EditPlan',
      hidden: true,
      component: () => import('@/views/plan/editPlan'),
      meta: { title: '编辑计划信息', icon: 'table' }
    },
    {
      path: 'addPlan',
      name: 'AddPlan',
      hidden: true,
      component: () => import('@/views/plan/addPlan'),
      meta: { title: '添加计划信息', icon: 'table' }
    }]
  },
  {
    path: '/student',
    component: Layout,
    redirect: '/student/studentList',
    children: [{
      path: 'studentList',
      name: 'studentList',
      component: () => import('@/views/student/studentList'),
      meta: { title: '学生信息管理', icon: 'dashboard' }
    },
    {
      path: 'editStudent',
      name: 'EditStudent',
      hidden: true,
      component: () => import('@/views/student/editStudent'),
      meta: { title: '编辑学生信息', icon: 'table' }
    },
    {
      path: 'addStudent',
      name: 'AddStudent',
      hidden: true,
      component: () => import('@/views/student/addStudent'),
      meta: { title: '添加学生信息', icon: 'table' }
    }]
  },

  {
    path: '/baoming',
    component: Layout,
    redirect: '/baoming/baomingList',
    meta: { title: '报名管理', icon: 'example' },
    children: [{
      path: 'baomingList',
      name: 'BaomingList',
      component: () => import('@/views/baoming/baomingList'),
      meta: { title: '可报名实验室', icon: 'dashboard' }
    },
    {
      path: 'shenhe',
      name: 'Shenhe',
      component: () => import('@/views/baoming/shenhe'),
      meta: { title: '审核报名信息', icon: 'table' }
    },
    {
      path: 'baoming',
      name: 'Baoming',
      hidden: true,
      component: () => import('@/views/baoming/baoming'),
      meta: { title: '报名信息填写', icon: 'table' }
    }]
  },

  {
    path: '/work',
    component: Layout,
    redirect: '/work/workList',
    children: [{
      path: 'workList',
      name: 'workList',
      component: () => import('@/views/work/workList'),
      meta: { title: '工作日志管理', icon: 'dashboard' }
    },
    {
      path: 'editWork',
      name: 'EditWork',
      hidden: true,
      component: () => import('@/views/work/editWork'),
      meta: { title: '编辑工作日志', icon: 'table' }
    },
    {
      path: 'addWork',
      name: 'AddWork',
      hidden: true,
      component: () => import('@/views/work/addWork'),
      meta: { title: '添加工作日志', icon: 'table' }
    }]
  },

  {
    path: '/repair',
    component: Layout,
    redirect: '/repair/repairList',
    children: [{
      path: 'repairList',
      name: 'RepairList',
      component: () => import('@/views/repair/repairList'),
      meta: { title: '维修信息管理', icon: 'dashboard' }
    },
    {
      path: 'editRepair',
      name: 'EditRepair',
      hidden: true,
      component: () => import('@/views/repair/editRepair'),
      meta: { title: '编辑维修信息', icon: 'table' }
    },
    {
      path: 'addRepair',
      name: 'AddRepair',
      hidden: true,
      component: () => import('@/views/repair/addRepair'),
      meta: { title: '添加计划', icon: 'table' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // 去掉url的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
